package com.monster.servlet;

import com.alibaba.fastjson.JSONArray;
import com.monster.pojo.Playlist;
import com.monster.pojo.Tag;
import com.monster.service.ListServiceImpl;
import com.monster.service.PlaylistService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/PlaylistByTagServlet")
public class PlaylistByTagServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String lable = request.getParameter("lable");
        Tag tag = new Tag();
        tag.setTagId(Long.parseLong(lable));
        PlaylistService playlistService = new ListServiceImpl();
        List<Playlist> playlists = playlistService.selectPlaylistByTag(tag,null,0,8);
     /*   for(Playlist list:playlists){
            System.out.println(list.getPlaylistId());
        }*/
        PrintWriter out = response.getWriter();
        out.print(JSONArray.toJSON(playlists));
        out.flush();
        out.close();
    }
}
